package bb.lanxing.util.ui;

import android.os.Handler;
import android.os.Message;
import java.lang.ref.WeakReference;

public abstract class BaseUIHandler<T> extends Handler {
    private WeakReference<T> uiTarget;

    public abstract void handleMessage(Message msg, T uiObj);

    public BaseUIHandler(T uiObj) {
        this.uiTarget = new WeakReference<>(uiObj);
    }

    public T getTarget() {
        return this.uiTarget.get();
    }

    @Override
    public final void handleMessage(Message msg) {
        T target = getTarget();
        if (target != null) {
            handleMessage(msg, target);
        }
    }
}
